package com.wedimob.slideshare;

import com.wedimob.slideshare.task.io.disk.DefaultWriter;
import com.wedimob.slideshare.task.io.network.DefaultReader;

public class RuntimeConfig {

	private static RuntimeConfig instance = new RuntimeConfig();

	public static RuntimeConfig getInstance() {
		return instance;
	}

	private Class<? extends Reader> readerClass = DefaultReader.class;
	private Class<? extends Writer> writerClass = DefaultWriter.class;
	private Reader reader;
	private Writer writer;
	private int timeout = 60;
	private int screenWidth = 800;
	private int screenHeight = 600;
	private String tmpdir = "tmp";
	private String outputdir = "output";
	private String rootpath = System.getProperty("user.dir");

	public Writer getWriter() {
		if (writer != null)
			return writer;

		try {
			writer = writerClass.newInstance();
			return writer;
		} catch (Exception e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		}
	}

	public Reader getReader() {
		if (reader != null)
			return reader;

		try {
			reader = readerClass.newInstance();
			return reader;
		} catch (Exception e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		}
	}

	public void setReader(Class<? extends Reader> readerClass) {
		this.readerClass = readerClass;
		try {
			reader = readerClass.newInstance();
		} catch (Exception e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		}
	}

	public void setWriter(Class<? extends Writer> writerClass) {
		this.writerClass = writerClass;
		try {
			writer = writerClass.newInstance();
		} catch (Exception e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		}
	}

	public int getTimeout() {
		return timeout;
	}

	public void setTimeout(int timeout) {
		this.timeout = timeout;
	}

	public int getScreenWidth() {
		return screenWidth;
	}

	public void setScreenWidth(int screenWidth) {
		this.screenWidth = screenWidth;
	}

	public int getScreenHeight() {
		return screenHeight;
	}

	public void setScreenHeight(int screenHeight) {
		this.screenHeight = screenHeight;
	}

	public String getTmpdir() {
		return tmpdir;
	}

	public void setTmpdir(String tmpdir) {
		this.tmpdir = tmpdir;
	}

	public String getOutputdir() {
		return outputdir;
	}

	public void setOutputdir(String outputdir) {
		this.outputdir = outputdir;
	}

	public String getRootpath() {
		return rootpath;
	}

	public void setRootpath(String rootpath) {
		this.rootpath = rootpath;
	}
}
